@extends('back.adminbase')
@section('content')
    <section class="hbox stretch">
        @include("back.public.left")

        <aside>
            <section class="vbox">

                <header class="header bg-white b-b clearfix">
                    <form class="talbe-search" method="get" action="">
                        <div class="row m-t-sm">
                            <div class="col-sm-12 m-b-xs">
                                <div class="btn-group" role="group">
                                    <strong style="line-height:30px;">编辑地区</strong>
                                </div>
                                <div class="btn-group pull-right">
                                    <a role="button" class="btn btn-info btn-sm " title="返回" onclick="history.back()">
                                        <i class="glyphicon glyphicon-arrow-left"></i>&nbsp;返回
                                    </a>
                                </div>
                            </div>
                        </div>
                    </form>
                </header>
                <section class="scrollable  wrapper w-f">
                    <section class="panel panel-default ">
                        <div class="row m-l-none m-r-none bg-light lter">
                            <div class="container" style="padding: 20px 0px">
                                <form id="formclass" class="form-horizontal" style="padding-top: 15px;">
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">上级地区类别<span class="red">*</span></label>
                                        <div class="col-sm-4 ">
                                            <select class="form-control input-sm" name="pid">
                                                <option value="0" selected="">顶级类别</option>
                                                @foreach($res as $v)
                                                    <option value="{{$v->id}} " @if($one->pid == $v->id)selected @endif>{{$v->name}} </option>
                                                @endforeach
                                            </select>
                                        </div>

                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">地区名称<span class="red"></span></label>
                                        <div class="col-sm-4 ">
                                            <input type="text" class="form-control" name="name" maxlength="20" value="{{$one->name}}"
                                                   placeholder="请输入名称">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-sm-3">状态<span class="red">*</span></label>
                                        <div class="col-sm-4">
                                            <input type="radio" id="status1" name="status" value="{{\App\Util\Status::ON}}" <?php if($one->status ==1): ?> checked <?php endif; ?>>
                                            <label for="status1">启用</label>
                                            <input type="radio" id="status0" name="status" value="{{\App\Util\Status::OFF}}" <?php if($one->status ==2): ?> checked <?php endif; ?>>
                                            <label for="status0">禁用</label>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label"></label>
                                        <div class="col-sm-2 ">
                                            <button role="button" class="btn btn-default" addparm="" type="submit">提交</button>
                                            <input type="checkbox" id="back">
                                            <label for="back">返回列表</label>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>

                    </section>
                </section>


            </section>
        </aside>
    </section>
@endsection
@section('addscript')
    <script>
        $(function(){
            $("#formclass").submit(function(){
                var pid=$("[name=pid]").val();
                var name=$("[name=name]").val();
                if(pid==''){
                    layer.msg("顶级分类不能为空");
                    return false;
                }
                if(name==''){
                    layer.msg("名称不能为空");
                    return false;
                }
                var status=$("[name=status]:checked").val();
                var back=$("#back").is(':checked');
                if(pid==""){
                    layer.alert("父类别不能为空！");
                    return false;
                }
                $.ajax({
                    url:"{{ url('back/region/edit/'.$one->id) }}",
                    type:"post",
                    dataType:"json",
                    data:{
                        pid:pid,
                        name:name,
                        status:status
                    },
                    success:function(data){
                        if(data.success){
                            layer.alert(data.msg,function(){
                                if (back) {
                                    location.href="{{url('back/region')}}";
                                } else {
                                    location.reload();
                                }
                            });
                        }
                        else{
                            layer.alert(data.msg);
                        }
                    }
                })
                return false;
            })


        });
    </script>
@endsection
